﻿Imports System
Imports System.IO
Imports FreeImageAPI
Imports FreeImageAPI.FreeImage
'Imports FI = Fireball.Drawing.FreeImage

Public Class Common
    Public Shared FilesPath As String
    Private _assetFileName As String

    Public Enum extensionTypes
        TextFiles = 1
        OggFiles = 2
        DdsFiles = 4
        JpgFiles = 8
        Mp3Files = 16
    End Enum


    Public Sub LoadFileList(ByVal FilePath As String, ByVal extensionType As extensionTypes, ByRef cmbBox As ComboBox)
        Dim strFileSize As String = ""
        cmbBox.Items.Clear()
        Dim di As New System.IO.DirectoryInfo(FilePath)
        Dim aryFi As System.IO.FileInfo() = di.GetFiles(getExtensionName(extensionType))
        Dim fi As System.IO.FileInfo

        For Each fi In aryFi
            cmbBox.Items.Add(fi.Name)
        Next

    End Sub

    Private Function getExtensionName(ByVal extensionType As extensionTypes) As String
        Dim retval As String = "*.*"
        Select Case extensionType
            Case extensionTypes.TextFiles
                retval = "*.txt"
            Case extensionTypes.OggFiles
                retval = "*.ogg"
            Case extensionTypes.DdsFiles
                retval = "*.dds"
            Case extensionTypes.JpgFiles
                retval = "*.jpg"
            Case extensionTypes.Mp3Files
                retval = "*.mp3"
        End Select
        getExtensionName = retval
    End Function

    Public Sub DrawImageOnPictureBox(ByVal vFileName As String, ByVal vImageType As FREE_IMAGE_FORMAT, ByRef vPictureBox As PictureBox)

        Dim mDib As FreeImageAPI.FIBITMAP
        mDib = FreeImageAPI.FreeImage.Load(vImageType, vFileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT)
        ' OLE_PICTURE is the StdPicture object, which can be drawn almost anywhere!
        vPictureBox.Image = FreeImageAPI.FreeImage.GetBitmap(mDib)
        FreeImageAPI.FreeImage.Unload(mDib)


        'Dim freeImage As FI
        'Try
        '    freeImage = New Fireball.Drawing.FreeImage(vFileName)
        '    vPictureBox.Image = freeImage.GetBitmap
        'Catch ex As Exception
        '    MsgBox(ex.ToString)
        'End Try


    End Sub
End Class
